const express=require('express');
const pool=require('../db')
const router=express.Router()
//接口  byd——register

router.post('/',(req,res)=>{
  console.log(req.body);
  const userinfo=req.body;
  const sqlStr='select * from byd_register where uname=?'
  pool.query(sqlStr,userinfo.uname,(err,r)=>{
    if(err){throw err}
    console.log(r);
    if(r.length){
    return  res.send('用户名被占用请更换其他用户名');
    }else{
      const sql='insert into byd_register (uname,upwd,rePwd,phone,email) values (?,?,?,?,?) '
  pool.query(sql,[userinfo.uname,userinfo.pwd,userinfo.rePwd,userinfo.phone,userinfo.email],(err,results)=>{
    if(err) throw err
    if(results.affectedRows!==1){
      res.send('注册用户失败')
      return 
    }else{
      res.send('注册成功')
    }
  })
  
    }
  })
})
module.exports=router